<!DOCTYPE html>
<html class="iframe-h" xmlns:th="http://www.thymeleaf.org">
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>网站后台管理模版</title>
		<link rel="stylesheet" type="text/css" th:href="@{/layui/css/layui.css}"/>
		<link rel="stylesheet" type="text/css" th:href="@{/css/admin.css}"/>
	</head>

	<body>
		<div class="wrap-container clearfix">
				<div class="column-content-detail">
					<form class="layui-form" action="">
						<div class="layui-form-item">
							<div class="layui-inline tool-btn">
								<button class="layui-btn layui-btn-small layui-btn-normal addText" data-url="/toAddText"><i class="layui-icon">&#xe654;</i></button>
								<button class="layui-btn layui-btn-small layui-btn-danger remove"  data-url="/removeTextData"><i class="layui-icon">&#xe640;</i></button>
								<button class="layui-btn layui-btn-small ayui-btn-normal modify"  data-url="/toModifyTextData"><i class="layui-icon">&#xe614;</i></button>
							</div>
							<!--<div class="layui-inline">
								<input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
							</div>-->

							<!--<button class="layui-btn layui-btn-normal" lay-submit="search">搜索</button>-->
						</div>
					</form>
					<table class="layui-table" lay-data="{height: 'full', cellMinWidth: 80,  limit:15,limits:[15,30],
						url:'/texts', page:true, id:'test'}" lay-filter="test" id="test">
						<thead>
						<tr>
							<th lay-data="{type:'checkbox'}">ID</th>
							<th lay-data="{field:'id',align:'center'}">id</th>
							<th lay-data="{field:'artLabelText',align:'center'}">标签</th>
							<th lay-data="{field:'artTitle', align:'center'}">标题</th>
							<th lay-data="{field:'artCreater', align:'center'}">创建人</th>
							<th lay-data="{field:'artLike', align:'center'}">喜欢数量</th>
							<th lay-data="{field:'artReadCount', align:'center'}">阅读数量</th>
							<th lay-data="{field:'view', align:'center',templet: '#wenzhang',event: 'viewText'}">内容</th>
							<th lay-data="{field:'createTime', align:'center',templet:'#timeFormat'}">创建时间</th>
							<th lay-data="{field:'status', align:'center',templet: '#isHot'}">是否置顶</th>
							<th lay-data="{field:'status', align:'center',templet: '#isTop'}">是否热门</th>
							<th lay-data="{field:'status', align:'center',templet: '#checkboxTpl'}">状态</th>
						</tr>
						</thead>
					</table>

				</div>
		</div>


		<script th:src="@{/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
		<script th:src="@{/js/common.js}" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" th:src="@{/js/basic/dateutil.js}"></script>
		<script type="text/html" id="isHot">
			<input type="checkbox" name="lock" value="{{d.id}}" title="热门" lay-filter="lockHot" {{ d.isHot == 1?'checked':''}}>
		</script>
		<script type="text/html" id="isTop">
			<input type="checkbox" name="lock" value="{{d.id}}" title="置顶" lay-filter="lockTop" {{ d.isTop == 1?'checked':''}}>
		</script>
		<script type="text/html" id="checkboxTpl">
			{{#  if(d.status== 0){ }}
			正常
			{{#  }else if(d.status== 9){ }}
			<p style="color: red;">删除</p>
			{{#  }}}
		</script>
		<script type="text/html" id="timeFormat">
			{{getFormatDateByLong(d.createTime,'yyyy-MM-dd hh:mm:ss') }}
		</script>

		<script type="text/html" id="wenzhang">
			<button class="layui-btn layui-btn-primary layui-btn-sm">点击查看</button>
		</script>
		<script>

            layui.config({
                base: '/js/module/'
            }).extend({
                dialog: 'dialog',
            });

			layui.use(['table','tree','jquery','dialog'], function() {
				var table = layui.table,
					form = layui.form,
                    $ = layui.jquery,
					tree = layui.tree,
                    dialog = layui.dialog;

                //获取当前iframe的name值
                var iframeObj = $(window.frameElement).attr('name');

				table.on('tool(test)', function(obj){
                    var data = obj.data;
                    if(obj.event === 'viewText'){
                        layer.open({
                            type: 1,
                            title: '预览文章',
                            /*closeBtn: 0,*/
                            area: ['80%', '80%'],
                            //skin: 'layui-layer-nobg', //没有背景色
                            shadeClose: false,
                            content: data.content
                        });
                    }
				});

                $('.addText').click(function() {
                    let url=$(this).attr('data-url');
                    //将iframeObj传递给父级窗口,执行操作完成刷新
                    page("新建文章", url, iframeObj, w = '80%', h = '80%');
                    return false;

                }).mouseenter(function() {

                    dialog.tips('新建文章', '.addText');

                });

                $('.modify').click(function() {
                    var checkStatus = table.checkStatus('test'),data = checkStatus.data;
                    if(data.length<1){
                        layer.msg("请选择一条记录")
                        return false;
                    }
                    if(data.length>1){
                        layer.msg("只能选择一条记录")
                        return false;
                    }
                    if(data[0].status === 9){
                        layer.msg("删除项不可修改！");
                        return false;
                    }
                    let url=$(this).attr('data-url');
                    url = url+"?id="+data[0].id;
                    //将iframeObj传递给父级窗口,执行操作完成刷新
                    page("设置", url, iframeObj, w = "80%", h = "80%");
                    return false;

                }).mouseenter(function() {

                    dialog.tips('设置', '.modify');

                });


                $('.remove').click(function() {
                    var checkStatus = table.checkStatus('test'),data = checkStatus.data;
                    if(data.length<1){
                        layer.msg("请选择一条记录")
                        return false;
                    }
                    if(data.length>1){
                        layer.msg("只能选择一条记录")
                        return false;
                    }
                    let url=$(this).attr('data-url');
                    if(data[0].status === 9){
                        layer.msg("不可删除！");
                        return false;
                    }
                    layer.confirm( '您确定要删除选中项',function(index){
                            url = url+"?id="+data[0].id;
                            $.ajax({
                                url:url,
                                type: 'post',
                                dataType:'json',
                                success:function (data){
                                    let result = JSON.stringify(data.data);
                                    if(result === "true"){
                                        layer.close(index);
                                        layer.msg("删除成功");
                                        table.reload('test',{page:{curr:1}});
                                    }
                                }
                            });
                    });
                    return false;

                }).mouseenter(function() {
                    dialog.tips('删除', '.remove');
                })


                form.on('checkbox(lockHot)', function(obj){
                    $.ajax({
                        url:'/toLockHotText?id='+this.value,
                        type: 'post',
                        dataType:'json',
                        success:function (data){
                            if(data.code === 200){
                                layer.msg("修改成功");
                            }else{
                                layer.msg(data.msg);
                                table.reload('test',{page:{curr:1}});
							}
                        }
                    });
                });


                form.on('checkbox(lockTop)', function(obj){
                    $.ajax({
                        url:'/toLockTopText?id='+this.value,
                        type: 'post',
                        dataType:'json',
                        success:function (data){
                            if(data.code === 200){
                                layer.msg("修改成功");
                            }else{
                                layer.msg(data.msg);
                                table.reload('test',{page:{curr:1}});
                            }
                        }
                    });
                });

            });

		</script>
	</body>

</html>